﻿namespace DotRas
{
    using System;
    using System.Collections.ObjectModel;
    using System.Diagnostics;

    [Serializable, DebuggerDisplay("Id = {Id}, Name = {Name}")]
    public sealed class RasCountry
    {
        private int _code;
        private int _id;
        private string _name;

        internal RasCountry(int id, int code, string name)
        {
            this._id = id;
            this._code = code;
            this._name = name;
        }

        public static ReadOnlyCollection<RasCountry> GetCountries()
        {
            Collection<RasCountry> list = new Collection<RasCountry>();
            int countryId = 1;
            do
            {
                RasCountry item = RasHelper.GetCountry(countryId, out countryId);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            while (countryId != 0);
            return new ReadOnlyCollection<RasCountry>(list);
        }

        public static RasCountry GetCountryById(int countryId)
        {
            int nextCountryId = 0;
            return RasHelper.GetCountry(countryId, out nextCountryId);
        }

        public override string ToString()
        {
            return this.Name;
        }

        public int Code
        {
            get
            {
                return this._code;
            }
        }

        public int Id
        {
            get
            {
                return this._id;
            }
        }

        public string Name
        {
            get
            {
                return this._name;
            }
        }
    }
}

